/*
Author: Surpass-HC
Source: https://gitee.com/hxchuan000/clpc-1
Mail: surpass-hc@qq.com
*/
#ifndef __LIGHT_COMMAND_LIST_H__
#define __LIGHT_COMMAND_LIST_H__
#include <clptcParse.h>

#if DEVICE_PLATFORM_CONFIGURE != DEVICE_PLATFORM_C51_MCU
#pragma pack(1)
#endif
// =============command rwSn(write or read serial number) begin=====================
typedef struct
{
    char wSn[CLPTC_SLAVE_SN_SIZE];
} clptcCmdStcSnd_rwSn;
typedef struct
{
    char rSn[CLPTC_SLAVE_SN_SIZE];
} clptcCmdStcResp_rwSn;
typedef union
{
    clptcCmdStcSnd_rwSn idt;
    clptcCmdStcResp_rwSn odt;
} clptcCmdUnion_rwSn;
void clptcCmdFuncOvtSnd_rwSn(clptcCmdStcSnd_rwSn *idt);
void clptcCmdFuncOvtResp_rwSn(clptcCmdStcResp_rwSn *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_rwSn(clptcParseStc *ptcptr, clptcCmdUnion_rwSn *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_rwSn(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_rwSn *packDt);
int clptcCmdFuncHostDoResp_rwSn(clptcParseStc *ptcptr, clptcCmdStcResp_rwSn *odt);
#endif
// =============command rwSn(write or read serial number) end======================

// =============command rwAddr(write or read address) begin=====================
typedef struct
{
    char cfgSn[CLPTC_SLAVE_SN_SIZE];
    uint8_t rwflag; // 0:read; 1:write
    uint8_t wAddr;  // write addr
} clptcCmdStcSnd_rwAddr;
typedef struct
{
    uint8_t rAddr; // read addr
} clptcCmdStcResp_rwAddr;
typedef union
{
    clptcCmdStcSnd_rwAddr idt;
    clptcCmdStcResp_rwAddr odt;
} clptcCmdUnion_rwAddr;
void clptcCmdFuncOvtSnd_rwAddr(clptcCmdStcSnd_rwAddr *idt);
void clptcCmdFuncOvtResp_rwAddr(clptcCmdStcResp_rwAddr *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_rwAddr(clptcParseStc *ptcptr, clptcCmdUnion_rwAddr *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_rwAddr(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_rwAddr *packDt);
int clptcCmdFuncHostDoResp_rwAddr(clptcParseStc *ptcptr, clptcCmdStcResp_rwAddr *odt);
#endif
// =============command rwAddr(write or read address) end======================

// =============command getInf begin=====================
typedef struct
{
    char reserve;
} clptcCmdStcSnd_getInf;
typedef struct
{
    char rvers[32]; // A-LPT-STD-V1.1.2407131959, [A表示应用程序APP,B表示引导程序BOOT]，[LPT:设备类型]，[STD:标准版]
    char rsn[CLPTC_SLAVE_SN_SIZE];
    char devInfo[16];
} clptcCmdStcResp_getInf;
typedef union
{
    clptcCmdStcSnd_getInf idt;
    clptcCmdStcResp_getInf odt;
} clptcCmdUnion_getInf;
void clptcCmdFuncOvtSnd_getInf(clptcCmdStcSnd_getInf *idt);
void clptcCmdFuncOvtResp_getInf(clptcCmdStcResp_getInf *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_getInf(clptcParseStc *ptcptr, clptcCmdUnion_getInf *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_getInf(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_getInf *packDt);
int clptcCmdFuncHostDoResp_getInf(clptcParseStc *ptcptr, clptcCmdStcResp_getInf *odt);
#endif
// =============command getInf end======================

// =============command setsm4key begin=====================
typedef struct
{
    char setkey[16];
} clptcCmdStcSnd_setsm4key;
typedef struct
{
    char keycrc[16];
} clptcCmdStcResp_setsm4key;
typedef union
{
    clptcCmdStcSnd_setsm4key idt;
    clptcCmdStcResp_setsm4key odt;
} clptcCmdUnion_setsm4key;
void clptcCmdFuncOvtSnd_setsm4key(clptcCmdStcSnd_setsm4key *idt);
void clptcCmdFuncOvtResp_setsm4key(clptcCmdStcResp_setsm4key *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_setsm4key(clptcParseStc *ptcptr, clptcCmdUnion_setsm4key *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_setsm4key(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_setsm4key *packDt);
int clptcCmdFuncHostDoResp_setsm4key(clptcParseStc *ptcptr, clptcCmdStcResp_setsm4key *odt);
#endif
// =============command setsm4key end======================

// =============command heartBeat begin=====================

typedef struct
{
    char hdata[16]; // command data.
} clptcCmdStcSnd_heartBeat;
typedef struct
{
    char hdata[16]; // response data.
} clptcCmdStcResp_heartBeat;
typedef union
{
    clptcCmdStcSnd_heartBeat idt;
    clptcCmdStcResp_heartBeat odt;
} clptcCmdUnion_heartBeat;
void clptcCmdFuncOvtSnd_heartBeat(clptcCmdStcSnd_heartBeat *idt);
void clptcCmdFuncOvtResp_heartBeat(clptcCmdStcResp_heartBeat *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_heartBeat(clptcParseStc *ptcptr, clptcCmdUnion_heartBeat *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_heartBeat(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_heartBeat *packDt);
int clptcCmdFuncHostDoResp_heartBeat(clptcParseStc *ptcptr, clptcCmdStcResp_heartBeat *odt);
#endif
// =============command heartBeat end======================

// =============command wrtFileBeg begin=====================
typedef struct
{
    uint32_t fileLen;
    uint16_t fileId;
} clptcCmdStcSnd_wrtFileBeg;
typedef struct
{
    uint16_t packSize;
    char optResult; // 0:ok, 1:fail, 2:dev reboot, 3:please wait and response later.
} clptcCmdStcResp_wrtFileBeg;
typedef union
{
    clptcCmdStcSnd_wrtFileBeg idt;
    clptcCmdStcResp_wrtFileBeg odt;
} clptcCmdUnion_wrtFileBeg;
void clptcCmdFuncOvtSnd_wrtFileBeg(clptcCmdStcSnd_wrtFileBeg *idt);
void clptcCmdFuncOvtResp_wrtFileBeg(clptcCmdStcResp_wrtFileBeg *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_wrtFileBeg(clptcParseStc *ptcptr, clptcCmdUnion_wrtFileBeg *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_wrtFileBeg(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_wrtFileBeg *packDt);
int clptcCmdFuncHostDoResp_wrtFileBeg(clptcParseStc *ptcptr, clptcCmdStcResp_wrtFileBeg *odt);
#endif
// =============command wrtFileBeg end======================

// =============command wrtFileSnd begin=====================
typedef struct
{
    uint32_t fileOffset;
    uint16_t fileId;
    uint16_t packLen;
    char packData[CLPTC_TSFR_FILE_LEN_MAX];
} clptcCmdStcSnd_wrtFileSnd;
typedef struct
{
    char optResult; // 0 ok, 1 fail
} clptcCmdStcResp_wrtFileSnd;
typedef union
{
    clptcCmdStcSnd_wrtFileSnd idt;
    clptcCmdStcResp_wrtFileSnd odt;
} clptcCmdUnion_wrtFileSnd;
void clptcCmdFuncOvtSnd_wrtFileSnd(clptcCmdStcSnd_wrtFileSnd *idt);
void clptcCmdFuncOvtResp_wrtFileSnd(clptcCmdStcResp_wrtFileSnd *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_wrtFileSnd(clptcParseStc *ptcptr, clptcCmdUnion_wrtFileSnd *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_wrtFileSnd(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_wrtFileSnd *packDt);
int clptcCmdFuncHostDoResp_wrtFileSnd(clptcParseStc *ptcptr, clptcCmdStcResp_wrtFileSnd *odt);
#endif
// =============command wrtFileSnd end======================

// =============command wrtFileFin begin=====================
typedef struct
{
    uint32_t fileLen;
    uint32_t fileCrc;
    uint16_t fileId;
} clptcCmdStcSnd_wrtFileFin;
typedef struct
{
    char optResult; // 0:ok, 1:fail
} clptcCmdStcResp_wrtFileFin;
typedef union
{
    clptcCmdStcSnd_wrtFileFin idt;
    clptcCmdStcResp_wrtFileFin odt;
} clptcCmdUnion_wrtFileFin;
void clptcCmdFuncOvtSnd_wrtFileFin(clptcCmdStcSnd_wrtFileFin *idt);
void clptcCmdFuncOvtResp_wrtFileFin(clptcCmdStcResp_wrtFileFin *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_wrtFileFin(clptcParseStc *ptcptr, clptcCmdUnion_wrtFileFin *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_wrtFileFin(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_wrtFileFin *packDt);
int clptcCmdFuncHostDoResp_wrtFileFin(clptcParseStc *ptcptr, clptcCmdStcResp_wrtFileFin *odt);
#endif
// =============command wrtFileFin end======================

// =============command readFileBeg begin=====================
typedef struct
{
    uint16_t fileId;
} clptcCmdStcSnd_readFileBeg;
typedef struct
{
    uint32_t fileLen;
    uint32_t fileCrc;
    uint16_t fileId;
    uint16_t packSize;
    char optResult; // 0:ok, 1:fail
} clptcCmdStcResp_readFileBeg;
typedef union
{
    clptcCmdStcSnd_readFileBeg idt;
    clptcCmdStcResp_readFileBeg odt;
} clptcCmdUnion_readFileBeg;
void clptcCmdFuncOvtSnd_readFileBeg(clptcCmdStcSnd_readFileBeg *idt);
void clptcCmdFuncOvtResp_readFileBeg(clptcCmdStcResp_readFileBeg *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_readFileBeg(clptcParseStc *ptcptr, clptcCmdUnion_readFileBeg *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_readFileBeg(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_readFileBeg *packDt);
int clptcCmdFuncHostDoResp_readFileBeg(clptcParseStc *ptcptr, clptcCmdStcResp_readFileBeg *odt);
#endif
// =============command readFileBeg end======================

// =============command readFileRcv begin=====================
typedef struct
{
    uint32_t fileOffset;
    uint16_t fileId;
    uint16_t packLen;
} clptcCmdStcSnd_readFileRcv;
typedef struct
{
    char optResult; // 0:ok, 1:fail
    char packData[CLPTC_TSFR_FILE_LEN_MAX];
} clptcCmdStcResp_readFileRcv;
typedef union
{
    clptcCmdStcSnd_readFileRcv idt;
    clptcCmdStcResp_readFileRcv odt;
} clptcCmdUnion_readFileRcv;
void clptcCmdFuncOvtSnd_readFileRcv(clptcCmdStcSnd_readFileRcv *idt);
void clptcCmdFuncOvtResp_readFileRcv(clptcCmdStcResp_readFileRcv *odt);
#if CLPTC_CPL_SUB_ENABLE
void clptcCmdFuncSubDo_readFileRcv(clptcParseStc *ptcptr, clptcCmdUnion_readFileRcv *iodt);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdFuncHostPack_readFileRcv(clptcParseStc *ptcptr, int packAddr, int packCrypt, clptcCmdStcSnd_readFileRcv *packDt);
int clptcCmdFuncHostDoResp_readFileRcv(clptcParseStc *ptcptr, clptcCmdStcResp_readFileRcv *odt);
#endif
// =============command readFileRcv end======================

#if DEVICE_PLATFORM_CONFIGURE != DEVICE_PLATFORM_C51_MCU
#pragma pack()
#endif

enum clptcCmdEnumList
{
    clptcCmdEnum_rwSn = 0,
    clptcCmdEnum_rwAddr,
    clptcCmdEnum_getInf,
    clptcCmdEnum_setsm4key,
    clptcCmdEnum_heartBeat,
    clptcCmdEnum_wrtFileBeg,
    clptcCmdEnum_wrtFileSnd,
    clptcCmdEnum_wrtFileFin,
    clptcCmdEnum_readFileBeg,
    clptcCmdEnum_readFileRcv,
};

#define clptcCmdEnumDef(sname) clptcCmdEnum_##sname

#if CLPTC_CPL_SUB_ENABLE
int clptcCmdSubDealByID(clptcParseStc *ptcptr);
#endif
#if CLPTC_CPL_HOST_ENABLE
int clptcCmdHostDealByID(clptcParseStc *ptcptr);
#endif

#define CAL_PARSE_BUFF_PERFECT_LEN (clptcPsComSize + CLPTC_PV1_PST_DATA + sizeof(clptcCmdUnion_wrtFileSnd))
#endif